'use strict'

define([ 'jquery', 'bootstrap', 'select2', 'shiftform', 'validate',
        'validate.en', 'datetimepicker', 'datetimepickerCN' ], function($) {
    return {
        init : function() {
           this.initSearch();
            this.initEdit();
            this.initCreate();
            this.initDelete();
            this.initPhase();
            this.initBindCourses();
            this.initBindTrainer();
            this.initEditCourse();
        },

               
        initSearch: function() {
              
            $(document).on('shown.bs.modal', '#search', function(e) {
              $('[name="beginDateFrom"]').datetimepicker({
                format: 'yyyy-mm-dd',
                language: 'zh-CN',
                autoclose: 1,
                clearBtn:true,//清除按钮
                minView: 2,
                forceParse: 0
              });
              
              $('[name="beginDateTo"]').datetimepicker({
                  format: 'yyyy-mm-dd',
                  language: 'zh-CN',
                  autoclose: 1,
                  clearBtn:true,//清除按钮
                  minView: 2,
                  forceParse: 0
                });
              
              $('[name="endDateFrom"]').datetimepicker({
                  format: 'yyyy-mm-dd',
                  language: 'zh-CN',
                  autoclose: 1,
                  clearBtn:true,//清除按钮
                  minView: 2,
                  forceParse: 0
                });
            
            $('[name="endDateTo"]').datetimepicker({
                format: 'yyyy-mm-dd',
                language: 'zh-CN',
                autoclose: 1,
                clearBtn:true,//清除按钮
                minView: 2,
                forceParse: 0
              });
          });
            
        },
        
        initEdit : function() {

            $(document).on('shown.bs.modal', '#edit', function(e) {

               $(document).find('form[data-validate="true"]').bt_validate() // bind
                                                                                // validate
              $('[name="phaseBeginDate"]').datetimepicker({
                  format: 'yyyy-mm-dd',
                  language: 'zh-CN',
                  autoclose: 1,
                  clearBtn:true,//清除按钮
                  minView: 2,
                  forceParse: 0
                });
                $('[name="phaseEndDate"]').datetimepicker({
                    format: 'yyyy-mm-dd',
                    language: 'zh-CN',
                    autoclose: 1,
                    clearBtn:true,//清除按钮
                    minView: 2,
                    forceParse: 0
                  });
                $('[name="beginDate"]').datetimepicker({
                    format: 'yyyy-mm-dd',
                    language: 'zh-CN',
                    autoclose: 1,
                    clearBtn:true,//清除按钮
                    minView: 2,
                    forceParse: 0
                  });
                  $('[name="endDate"]').datetimepicker({
                      format: 'yyyy-mm-dd',
                      language: 'zh-CN',
                      autoclose: 1,
                      clearBtn:true,//清除按钮
                      minView: 2,
                      forceParse: 0
                    });

                var $form = $(document).find("form") // bind shiftform
                $form.shiftform({
                    beforeSubmit : function(el) {
                        $form.trigger("validate.ajax.submit");
                        return $.bt_validate.result[$.bt_validate.form_id]
                    }
                })
            });
        },        

        
         initPhase : function() {

            $(document).on('shown.bs.modal', '#phase', function(e) {

               $(document).find('form[data-validate="true"]').bt_validate() // bind
                                                                                // validate
              $('[name="beginDate"]').datetimepicker({
                  format: 'yyyy-mm-dd',
                  language: 'zh-CN',
                  autoclose: 1,
                  clearBtn:true,//清除按钮
                  minView: 2,
                  forceParse: 0
                });
                $('[name="endDate"]').datetimepicker({
                    format: 'yyyy-mm-dd',
                    language: 'zh-CN',
                    autoclose: 1,
                    clearBtn:true,//清除按钮
                    minView: 2,
                    forceParse: 0
                  });
                  
                var $form = $(document).find("form") // bind shiftform
                $form.shiftform({
                    beforeSubmit : function(el) {
                        $form.trigger("validate.ajax.submit");
                        return $.bt_validate.result[$.bt_validate.form_id]
                    }
                })
            });

        },        
        initDelete : function() {

            $(document).on('shown.bs.modal', '#delete', function(e) {

                $(document).find('form[data-validate="true"]').bt_validate() // bind
                                                                                // validate

                var $form = $(document).find("form") // bind shiftform
                $form.shiftform({
                    beforeSubmit : function(el) {
                        $form.trigger("validate.ajax.submit");
                        return $.bt_validate.result[$.bt_validate.form_id]
                    }
                })
            });

        },

        
        initBindCourses : function() {

            $(document).on('shown.bs.modal', '#bind-courses', function(e) {

                $(document).find('form[data-validate="true"]').bt_validate() // bind
                                                                                // validate

                var $form = $(document).find("form") // bind shiftform
                $form.shiftform({
                    beforeSubmit : function(el) {
                        $form.trigger("validate.ajax.submit");
                        return $.bt_validate.result[$.bt_validate.form_id]
                    }
                })
            });

        },
        
        initBindTrainer : function() {

            $(document).on('shown.bs.modal', '#bind-trainer', function(e) {

                $(document).find('form[data-validate="true"]').bt_validate() // bind
                                                                                // validate

                var $form = $(document).find("form") // bind shiftform
                $form.shiftform({
                    beforeSubmit : function(el) {
                        $form.trigger("validate.ajax.submit");
                        return $.bt_validate.result[$.bt_validate.form_id]
                    }
                })
            });

        },
        
        initEditCourse : function() {

            $(document).on('shown.bs.modal', '#edit-course', function(e) {

                $(document).find('form[data-validate="true"]').bt_validate() // bind
                                                                                // validate

                var $form = $(document).find("form") // bind shiftform
                $form.shiftform({
                    beforeSubmit : function(el) {
                        $form.trigger("validate.ajax.submit");
                        return $.bt_validate.result[$.bt_validate.form_id]
                    }
                })
            });

        },
        
        initCreate : function() {
        	
            $(document).on('shown.bs.modal', '#create', function(e) {
                
            	
                
                $(document).find('form[data-validate="true"]').bt_validate() // bind
                                                                                // validate
                   
              	
              	
              
             var $form = $(document).find("form") // bind shiftform
              $form.shiftform({
                   beforeSubmit : function(el) {
                        $form.trigger("validate.ajax.submit");
                       return  $.bt_validate.result[$.bt_validate.form_id];
                        
                    }
               })
           });
        }
    }
})
